'''
* @name Maiji
* @author pd87@qq.com
* @copyright m-j.cc
'''
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import pymysql
import os

# 网页请求
def httpget(url,data = '',cookies = '',headers = '',allow_redirects = False,timeout = 15):
	if data:
		return requests.post(url = url,data = data,cookies = cookies,headers = headers,allow_redirects = allow_redirects,timeout = timeout)
	else:
		return requests.get(url = url,cookies = cookies,headers = headers,allow_redirects = allow_redirects,timeout = timeout)

# 数据库配置		
def query(querys):
	db = pymysql.connect('localhost','root','root','mm131',charset='utf8')
	_mysql = db.cursor()
	_mysql.execute(querys)
	data = _mysql.fetchall()
	db.commit()
	db.close()
	return data

# 字符串替换
def replace(text):
	text.replace(u'\xa9','')
	text.replace(u'\ufffd','')
	return text


def ximg(filename,data):
	path = filename[::-1]
	path = path[path.find('/'):][::-1]
	if os.path.exists(path) == False:
		os.makedirs(path)
	with open(filename,'wb') as file:
		file.write(data)